package com.xin.di.uav.applet.controller;

import com.xin.di.uav.applet.service.IOrderInfoService;
import com.xin.di.uav.common.request.order.FlightRequest;
import com.xin.di.uav.common.utils.Rs;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.security.SecureRandom;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

/**
 * @author LTQ
 */
@RestController
@RequestMapping("/home/order/")
public class OrderPublicController {
    private final static Logger logger = LoggerFactory.getLogger(OrderPublicController.class);



    @Autowired
    private IOrderInfoService iOrderInfoService;


    @PostMapping("refund-confirm")
    public String refundConfirmPay(HttpServletRequest httpServletRequest) {
        Enumeration<String> names = httpServletRequest.getParameterNames();
        Map<String, String> params = new HashMap<>();
        while (names.hasMoreElements()) {
            String k = names.nextElement();
            String v = httpServletRequest.getParameter(k);
            if (v == null || v.isEmpty()) {
                continue;
            }
            try {
                params.put(k, URLDecoder.decode(v, "utf-8"));
            } catch (UnsupportedEncodingException ignored) {
            }
        }

        logger.info("转换前参数是：" + params);
        return "success";
    }

    @PostMapping("confirm")
    public String confirmPay(HttpServletRequest httpServletRequest) {
        if (new SecureRandom().nextBoolean()) {
            System.out.println("进入另一个流程了，another flow");
        }
        logger.info("进入支付确认");
        return "success";
    }


}
